package com.sky.mapper;

import com.sky.annotation.AutoFill;
import com.sky.dto.EmployeeDTO;
import com.sky.entity.Employee;
import com.sky.enumeration.OperationType;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface EmployeeMapper {

    /**
     * 根据用户名查询员工
     *
     * @param username
     * @return
     */
    @Select("select * from employee where username = #{username}")
    Employee getByUsername(String username);


    /**
     * 添加员工
     *
     * @AutoFill(OperationType.UPDATE) 自动补充 修改人、修改时间
     */
    @Insert("INSERT INTO employee(name, username, password, phone, sex, id_number, status, create_time, update_time, create_user, update_user) " +
            "VALUES(#{name}, #{username}, #{password}, #{phone}, #{sex}, #{idNumber}, #{status}, #{createTime}, #{updateTime}, #{createUser}, #{updateUser})")
    @AutoFill(value = OperationType.INSERT)
    void insert(Employee employee);

    /*
     * 启用、禁用员工账号
     * */
    @Update("update employee SET status = #{status}," +
            "update_time =#{updateTime}," +
            "update_user =#{updateUser} " +
            "WHERE id = #{id}")
    @AutoFill(value = OperationType.UPDATE)
    void EnableDisableEmployee(Employee employee);


    @Select("select id,id_number,name,phone,sex,username from employee where id = #{id}")
    EmployeeDTO idEmployee(Integer id);


    /**
     * 员工修改密码
     *
     * @AutoFill(OperationType.UPDATE) 自动补充 修改人、修改时间
     */
    @AutoFill(OperationType.UPDATE)
    @Update("update employee SET password =#{password},update_time =#{now},update_user=#{currentId} WHERE id = #{stringID}")
    void editPassword(Employee employee);


    /**
     * 修改密码，查询当前密码
     */
    @Select("select * from employee where id = #{stringID}")
    Employee idEmployeePassword(String stringID);


    /**
     * 员工分页，条件查询
     */
    List<Employee> page(String name);


    /**
     * 编辑员工信息
     *
     * @AutoFill(OperationType.UPDATE) 自动补充 修改人、修改时间
     */
    @AutoFill(value = OperationType.UPDATE)
    void EditorialStaff(Employee employee);


}
